<?php

namespace App\Models\Used;

use App\Models\User\WxUser;
use App\Models\WxChat;
use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class WxUsedGood extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'wx_used_good';
    public $timestamps = false;

    protected static function boot()
    {
        parent::boot();
        static::deleted(function ($model) {
            WxChat::where('expand_type', 106)->where('expand_id', $model->id)->forceDelete();
        });
    }

    public function getImageUrlsAttribute($value)
    {
        if(_empty_($value)){
            return [];
        }
        return json_decode($value, true);
    }

    public function ower()
    {
        return $this->hasOne(WxUser::class, 'id', 'user_id');
    }

}
